<template>
    <el-button size="small" type="text" @click="copyLink">
      复制链接
    </el-button>
  </template>
  
  <script>
  import { ElMessage } from 'element-plus';
  
  export default {
    name: 'Copylink',
    props: {
      url: {
        type: String,
        required: true,
      },
    },
    methods: {
      copyLink() {
        navigator.clipboard.writeText(this.url)
          .then(() => {
            ElMessage({
              message: '链接已复制到剪贴板',
              type: 'success',
            });
          })
          .catch(() => {
            ElMessage.error('复制失败，请重试');
          });
      },
    },
  };
  </script>
  
  <style scoped>
  /* 如果需要自定义样式，可以在这里添加 */
  </style>
  